package com.cctc.mychat.client.handler;

import com.cctc.mychat.common.protocol.message.impl.response.ChatResponseMessage;
import com.cctc.mychat.common.util.JsonUtils;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class ChatResponseMessageHandler extends SimpleChannelInboundHandler<ChatResponseMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, ChatResponseMessage response) throws Exception {
        System.out.println("[ChatResponseMessageHandler] 聊天消息：" + JsonUtils.toJson(response));

        if (response.isSuccess()) {
            System.out.printf("收到 {%s} 发送过来的消息，内容为：%s", response.getFromUserName(), response.getData());
        } else {
            System.err.println("发送失败，原因：" + response.getReason());
        }
    }
}
